/**
 * 详情对话框
 */
var OrderFormInfoDlg = {
    data: {
            orderNo:""
            ,userId:""
            ,wasteId:""
            ,wasteWeight:""
            ,price:""
            ,totalPrice:""
            ,createTime:""
            ,state:""
            ,binsId:""
            ,finishTime:""
            ,errorCode:""
            ,errorMsg:""
    }
};

layui.use(['form', 'ax','laydate','admin'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    // 让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var validation = new Validation($("#orderFormForm")[0], {onSubmit:false});
        var validate = validation.validate();
        if(validate){
            var ajax = new $ax(Feng.ctxPath + "/orderForm/addItem", function (data) {
                Feng.success("添加成功！");
                //window.location.href = Feng.ctxPath + "/orderForm";
                //传给上个页面，刷新table用
                admin.putTempData('formOk', true);

                //关掉对话框
                admin.closeThisDialog();
            }, function (data) {
                Feng.error("添加失败！" + data.responseJSON.message)
            });
            ajax.set(data.field);
            ajax.start();
            //imagePathUploader.upload();
        }else{
            var serializeArray = $(".validation-failed");
            var errMsgs = "";
            for(var i=0;i<serializeArray.length;i++){
                var elemInfo = serializeArray[i];
                var elem = $("#"+elemInfo.name)[0];
                if(elem && elem.tooltip){
                    errMsgs+="<div><span style='color:dodgerblue'>"+elem.placeholder+"输入框有误：</span><span style='color:red'>"+elem.tooltip.content+"</span></div>"
                    var tipElem = elem.tagName=="SELECT"?$(elem).next():elem;
                    layer.tips(elem.tooltip.content,tipElem,{
                        tips: [1, '#FF99CC'],
                        time: 4000,
                        tipsMore: true
                    });
                }
            }
            //Feng.error(errMsgs);
        }
        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + "/orderForm";
    });
    var laydate = layui.laydate;
    lay('.datetime-input').each(function(){
        laydate.render({
            elem: this
            ,trigger: 'click'
            ,type: 'datetime'
        });
    });
});